var dialogDivs = new Array();

function HnlDialogObj(dialogDivSelector, dialogOpenSelector, actionUrl) {
	this.dialogDiv = $(dialogDivSelector);
	this.dialogOpenElement = $(dialogOpenSelector);
	this.actionUrl = actionUrl;
	this.autoOpen = false;
	this.height = 280;
	this.width = 420;
	this.modal = true;
	this.dialogObj = null;
	dialogDivs.push(this.dialogDiv);
}

HnlDialogObj.prototype.buildDialog = function() {
	var objReference = this; // used for inner callback functions

	this.dialogObj = this.dialogDiv.dialog({
		autoOpen : this.autoOpen,
		height : this.height,
		width : this.width,
		modal : this.modal
	});

	$(this.dialogOpenElement).each(function() {
		$(this).click(function() {
			objReference.dialogDiv.dialog("open");
		});
	});
}

HnlDialogObj.prototype.addDialogFunctions = function(confirmFunction) {
	var objReference = this; // used for inner callback functions

	var confirmFunctionObj;
	if (typeof confirmFunction != "undefined" && confirmFunction != null) {
		confirmFunctionObj = confirmFunction;
	} else {
		confirmFunctionObj = function() {
			$(this).dialog("close");
			if (typeof objReference.actionUrl != "undefined"
					&& objReference.actionUrl != null) {
				var form = objReference.dialogOpenElement.closest("form");
				form.attr("action", objReference.actionUrl);
				form.attr("method", "post");
				form.submit();
			}
		}
	}

	this.dialogDiv.dialog({
		buttons : {
			Confirm : confirmFunctionObj,
			Cancel : function() {
				$(this).dialog("close");
			}
		}
	});
}

HnlDialogObj.prototype.removeDialog = function() {
	this.dialogDiv.dialog("destroy");
}

function destroyHNLTabDialogs() {
	while (dialogDivs.length > 0) {
		divToRemove = dialogDivs.pop();
		divToRemove.remove();
	}
}